package main

import (
	"fmt"
	"gin_test/routers"
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

func main() {
	// 创建路由
	r := gin.Default()
	// 绑定路由规则
	r.GET("/test", func(c *gin.Context) {
		c.String(http.StatusOK, "hello world!")
	})
	r.GET("/user/:name/*action", func(c *gin.Context) {
		name := c.Param("name")
		action := c.Param("action")
		// 截取
		action = strings.Trim(action, "/")
		c.String(http.StatusOK, name+" is "+action)
	})
	r.GET("/user", func(c *gin.Context) {
		name := c.DefaultQuery("name", "你好") // 默认值
		c.String(http.StatusOK, fmt.Sprintf("hello %s", name))
	})

	r.Run(":8000")
}
